<?php
/**
 * 返款支付模型
 * (model)
 */
namespace App\Models\Reimburse;

use App\Models\Basics\Currency;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
class ReimbursePaid extends Model
{
    protected $table = 'reimburse_paid';

    protected $guarded = [];

    public static $_applyStatus = [
        1 => '未申请',
        2 => '已申请'
    ];

    public static $_auditStatus = [
        1 => '未审核',
        2 => '已审核'
    ];

    public static $_paidStatus = [
        1 => '未付款',
        2 => '已付款'
    ];

    //完全付款标志
    public static $_paidFlag = [
        0 => '部分付款',
        1 => '完全付款'
    ];

    public static $_status = [
        1 => '正常订单',
        2 => '问题订单',
        3 => '问题已处理'
    ];

    public static $_orderBy = [
        1 => '一次性付款',
        2 => '第一次付款',
        3 => '第二次付款',
        4 => '佣金'
    ];

    /**
     * 返款申请
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function apply(){
        return $this->belongsTo(ReimburseApply::class,'reimburse_no','reimburse_no');
    }

    /**
     * 货币
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function currency()
    {
        return $this->belongsTo(Currency::class,'currency_code','code');
    }

    public static function getImage($value, $width = 30, $height = 30, $server = ''){
        if(!$value){
            return '';
        }else{
            if (url()->isValidUrl($value)) {
                $src = $value;
            } elseif ($server) {
                $src = $server.$value;
            } else {
                $src = Storage::disk(config('admin.upload.disk'))->url($value);
            }
            return "<a href='$src' target='_blank' data-lightbox='e1'><img src='$src' style='max-width:{$width}px;max-height:{$height}px' class='img'></a>";
        }
    }

    /**
     * MAX(1)未
     * MIN(3)已
     * ELSE 部分
     * @param $status
     * @return int
     */
    public static function extractStatus($status){
        if(max($status) == 1)return 1;
        if(min($status) == 2)return 3;
        return 2;
    }
}
